<?php // register.php
require_once('./inc/inc.common.php');
$tmpl 		= new mvTemplate();
$tmpl->page_title('Register');

if(isset($_POST['submit'])) {
	$go = true;

	// Check for a first name.
	if(!eregi ("^[[:alpha:].' -]{2,15}$", trim($_POST['first_name']))) {
		$go = FALSE;
		mvError::userError('Registration Error', 'Please enter your first name!');
	}

	// Check for a last name.
	if(!eregi ("^[[:alpha:].' -]{2,30}$", trim($_POST['last_name']))) {
		$go = FALSE;
		mvError::userError('Registration Error', 'Please enter your last name!');
	}

	// Check for an email address.
	if(!eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", trim($_POST['email']))) {
		$go = FALSE;
		mvError::userError('Registration Error', 'Please enter a valid email address!');
	}

	// Check for a username.
	if(!eregi ("^[[:alnum:]_]{4,20}$", trim($_POST['username']))) {
		$go = FALSE;
		mvError::userError('Registration Error', 'Please enter a valid username!');
	}

	// Check for a password and match against the confirmed password.
	if ( strlen($_POST['password1']) > 4 ) {
		if($_POST['password1'] != $_POST['password2']) {
			$go = FALSE;
			mvError::userError('Registration Error', 'Your password did not match the confirmed password!');
		}
	}else{
		$go = FALSE;
		mvError::userError('Registration Error', 'Please enter a valid password!');
	}

	if($go){
		if($a = author::create(trim($_POST['username']), trim($_POST['first_name']), trim($_POST['last_name']), trim($_POST['email']), $_POST['password1'])){
			mvError::userNotice('Registration Successful', 'Your registration was successful, please login.');
			header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/login.php");
			exit();
		}else{
			mvError::userError('Registration Error', 'Sorry that username is taken.  Please choose another.');
		}
	}
}

$tmpl->page_display('register.tpl');

?>